package cn.gcyl.module.biz.controller.admin.contactplatform;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import cn.gcyl.framework.excel.core.util.ExcelUtils;
import cn.gcyl.module.biz.controller.admin.contactplatform.vo.*;
import cn.gcyl.module.biz.dal.dataobject.contactplatform.ContactPlatformDO;
import cn.gcyl.module.biz.service.contactplatform.ContactPlatformService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 联系平台")
@RestController
@RequestMapping("/biz/contact-platform")
@Validated
public class ContactPlatformController {

    @Resource
    private ContactPlatformService contactPlatformService;

//    @PostMapping("/create")
//    @Operation(summary = "创建联系平台")
//    @PreAuthorize("@ss.hasPermission('biz:contact-platform:create')")
//    public CommonResult<Long> createContactPlatform(@Valid @RequestBody ContactPlatformSaveReqVO createReqVO) {
//        return success(contactPlatformService.createContactPlatform(createReqVO));
//    }

    @PutMapping("/update")
    @Operation(summary = "更新联系平台")
//    @PreAuthorize("@ss.hasPermission('biz:contact-platform:update')")
    public CommonResult<Boolean> updateContactPlatform(@Valid @RequestBody ContactPlatformSaveReqVO updateReqVO) {
        contactPlatformService.updateContactPlatform(updateReqVO);
        return success(true);
    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除联系平台")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('biz:contact-platform:delete')")
//    public CommonResult<Boolean> deleteContactPlatform(@RequestParam("id") Long id) {
//        contactPlatformService.deleteContactPlatform(id);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete-list")
//    @Parameter(name = "ids", description = "编号", required = true)
//    @Operation(summary = "批量删除联系平台")
//                @PreAuthorize("@ss.hasPermission('biz:contact-platform:delete')")
//    public CommonResult<Boolean> deleteContactPlatformList(@RequestParam("ids") List<Long> ids) {
//        contactPlatformService.deleteContactPlatformListByIds(ids);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @Operation(summary = "获得联系平台")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('biz:contact-platform:query')")
    public CommonResult<ContactPlatformRespVO> getContactPlatform(@RequestParam("id") Long id) {
        ContactPlatformDO contactPlatform = contactPlatformService.getContactPlatform(id);
        return success(BeanUtils.toBean(contactPlatform, ContactPlatformRespVO.class));
    }
//
    @GetMapping("/page")
    @Operation(summary = "获得联系平台分页")
    @PreAuthorize("@ss.hasPermission('biz:contact-platform:query')")
    public CommonResult<PageResult<ContactPlatformRespVO>> getContactPlatformPage(@Valid ContactPlatformPageReqVO pageReqVO) {
        PageResult<ContactPlatformDO> pageResult = contactPlatformService.getContactPlatformPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ContactPlatformRespVO.class));
    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出联系平台 Excel")
//    @PreAuthorize("@ss.hasPermission('biz:contact-platform:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportContactPlatformExcel(@Valid ContactPlatformPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<ContactPlatformDO> list = contactPlatformService.getContactPlatformPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "联系平台.xls", "数据", ContactPlatformRespVO.class,
//                        BeanUtils.toBean(list, ContactPlatformRespVO.class));
//    }

}